package com.sc.controller;

import com.sc.pojo.Application;
import com.sc.pojo.User;
import com.sc.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @author 陈远坤
 */
@Controller
@RequestMapping("/application")
public class ApplicationController {
    @Autowired
    ApplicationService as;
    //添加申请
    @RequestMapping("/addapp")
    public String addapp(Integer acceptid, HttpSession session,String contents){
        System.out.println("接收方id"+acceptid);
        User u1 = (User)session.getAttribute("theUser");
        Application app = new Application();
        app.setSendid(u1.getId());
        app.setContents(contents);
        app.setAcceptid(acceptid);
        app.setCreatetime(new Date());
        as.addapp(app);
        return "redirect:/friends/selectFriends";
    }
    //删除申请
    @RequestMapping("/deleteapp")
    public String deleteapp(Integer sendid,HttpSession session){
        User u1 = (User)session.getAttribute("theUser");
        as.deleteBySendId(sendid,u1.getId());
        return "forward:/friends/selectFriends";
    }
}
